#pragma once

#include "../common/Util.hpp"
#include "../common/Log.hpp"
#include <ctemplate/template.h>
#include "oj_model.hpp"
#include <vector>
#include <string>
namespace ns_view{

    using namespace ns_Util;
    using namespace ns_model;
    using namespace std;
    class view{
        
        const std::string template_path = "./template/";
        const std::string all_question_template = "all_question.html";
        const std::string one_question_template = "one_question.html";
        public:
        bool AllExpand(const vector<Question>& all,std::string* html)
        {
            //1.获取html 路径
            std::string src_html = template_path + all_question_template;

            //2.数字字典
            ctemplate::TemplateDictionary root("all_questions");
            for(const auto& q:all)
            {
                ctemplate::TemplateDictionary* sub = root.AddSectionDictionary("question_list");
                sub->SetValue("number",q._number);
                sub->SetValue("title",q._title);
                sub->SetValue("degreeOfDifficult",q._degreeOfDifficult);
            }
            ctemplate::Template *tpl = ctemplate::Template::GetTemplate(src_html,ctemplate::DO_NOT_STRIP);

            tpl->Expand(html, &root);
            return 1;
        }
        bool OneExpand(const Question& one,std::string* html)
        {
            std::string src_html = template_path + one_question_template;
            ctemplate::TemplateDictionary root("one_question");
            root.SetValue("number",one._number);
            root.SetValue("title",one._title);
            root.SetValue("degreeOfDifficult",one._degreeOfDifficult);
            root.SetValue("desc",one._desc);
            root.SetValue("header_cpp",one._header_cpp);

            ctemplate::Template *tpl = ctemplate::Template::GetTemplate(src_html,ctemplate::DO_NOT_STRIP);

            tpl->Expand(html, &root);
            return 1;
        }
    };
};